package main;

import java.util.Vector;

import main.BackPropagation.Data;

public class NeuralNetwork {
	protected Vector<InputNeuron> inputNeurons;
	protected Vector<Vector<Neuron> > hiddenNeurons;
	protected Vector<Neuron> outputNeurons;

	public NeuralNetwork(Vector<InputNeuron> inputNeurons, Vector<Vector<Neuron> > hiddenNeurons, Vector<Neuron> outputNeurons){
		this.inputNeurons = inputNeurons;
		this.hiddenNeurons = hiddenNeurons;
		this.outputNeurons = outputNeurons;
	}

	public void reset() {
		for (Neuron n: inputNeurons){
			n.reset();
		}

		for (Vector<Neuron> vn: hiddenNeurons){
			for(Neuron n: vn){
				n.reset();
			}
		}
		for (Neuron n: outputNeurons){
			n.reset();
		}
	}
	
	public int[] testData(Vector<Integer> set, Data[][] data){
		int total = 0;
		int succ = 0;
		for (int i=0; i<set.size(); i++){
			for (int j=0; j<data.length; j++){
				Data d = data[j][set.get(i)];
				boolean ans = testOut(d);
				if (ans){
					succ++;
				}
				total++ ;
			}
		}
		return new int[]{succ, total};
	}
	
	public boolean testOut(Data data) {
		boolean ans = true;
		reset();

		for (InputNeuron n: inputNeurons){
			n.setValue(data.ins.get(n));
		}

		for (Neuron n: outputNeurons){
			if (n.getValue() != data.outs.get(n).doubleValue()){
				ans = false;
			}
		}
		return ans;
	}
}
